<?php
/**
 * UserInfo.php
 *
 * This page is for users to view their account information
 * with a link added for them to edit the information.
 *
 * Updated by: The Angry Frog
 * Last Updated: August 26, 2004
 */
include("header.php");
//invalid URL, redirect to index page
if (!isset($_GET['user'])) { 
	//header("Location: ".$config['WEB_ROOT'].$config['home_page']);
	header("Location: index.php");
}
else {
/* Requested Username error checking */
$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||!preg_match("/^[a-z0-9]([0-9a-z_-])+$/i", $req_user) || !$database->usernameTaken($req_user))
{
	header('refresh:3; url=index.php');?>
    <div id="form_container">
        <div id="title_container">
            <div id="title">
                <p>User Account</p>
            </div>
            <div id="title_link">
            </div>
        </div>
        <div id="form_content">
            <div id="form_text" style="padding:4px; border:1px solid ref; color:red;">Username Not Registered</div>
            <div id="form_text">Make Sure That You Are Logged In. Mean While, You Will Be Redirected To The Home Page</div>
        </div>
	</div>
	<?php 
	include("footer.php");
	die();
}

/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0)
{?>
	<div id="form_container">
        <div id="title_container">
            <div id="title">
                <p>My Account</p>
            </div>
            <div id="title_link">
				<?php /* If logged in user viewing own account, give link to edit */
                if(strcmp($session->username,$req_user) == 0)
                {
                   echo "<p><a href='useredit.php'>Edit Account</a> | <a href='javascript:history.back(-1)'>Back</a><p>";
                }?>
            </div>
        </div>
<?php }
/* Visitor not viewing own account */
else
{?>
	<div id="form_container">
    	<div id="title_container">
            <div id="title">
                <p>User Account</p>
            </div>
            <div id="title_link">
                <p><a href="javascript:history.back(-1)">Back</a></p>
            </div>
        </div>
<?php }
	/* Display requested user information */
	$req_user_info = $database->getUserInfo($req_user);
	$req_org_info = $database->getOrgInfo($req_user_info['orgID']);?>
    	<div id="form_content">
        <form id="form">
        	<ul>
            <fieldset><legend>Personal Information</legend>
                <li id="li_username">
                <label id="label_username" for="username">Username</label>
                <input id="username" type="text" name="username" disabled size="30" value="<?php echo $req_user_info['username'];?>" />
                </li>
                <li id="li_firstName">
                <label id="label_firstName" for="firstName">First Name</label>
                <input id="firstName" type="text" name="firstName" disabled size="30" value="<?php echo $req_user_info['firstName'];?>" />
                </li>
                <li id="li_lastName">
                <label id="label_lastName" for="lastName">Last Name</label>
                <input id="lastName" type="text" name="lastName" disabled size="30" value="<?php echo $req_user_info['lastName'];?>" />
                </li>
           	</fieldset>
            <fieldset><legend>Contact Information</legend>
                <li id="li_phoneNumber">
                <label id="label_phoneNumber" for="phoneNumber">Phone Number</label>
                <input id="phoneNumber" type="text" name="phoneNumber" disabled size="30" 
                	value="(<?php echo $req_user_info['areaCode'];?>) <?php echo $req_user_info['prefix'];?>-<?php echo $req_user_info['lineNumber'];?> x<?php echo $req_user_info['lineExt'];?>" />
                </li>
                <li id="li_email">
                <label id="label_email" for="email">Email</label>
                <input id="email" type="text" name="email" disabled size="30" value="<?php echo $req_user_info['email'];?>" />
                </li>
          	</fieldset>
            <fieldset><legend>About User</legend>
                <li id="li_about">
                <textarea id="about" type="text" name="about" class="large" disabled><?php echo $req_user_info['about'];?></textarea>
                </li>
            </fieldset>
            <fieldset><legend>Organization Information</legend>
            	<li id="li_orgName">
                <label id="label_orgName" for="orgName">Organization Name</label>
                <input id="orgName" type="text" name="orgName" disabled="disabled" size="30" value="<?php echo $req_org_info['orgName'];?>" />
                </li>
            </fieldset>
			</ul>
		</form>
        </div>
</div>
<?php
/**
* Note: when you add your own fields to the users table
* to hold more information, like homepage, location, etc.
* they can be easily accessed by the user info array.
*
* $session->user_info['location']; (for logged in users)
*
* ..and for this page,
*
* $req_user_info['location']; (for any user)
*/
}
include('footer.php');?>